import request from '@/utils/request'

// 登录
export function login(data) {
  return request({
    url: '/api/auths/login',
    method: 'post',
    data,
  })
}

// 登出
export function logout() {
  return request({
    url: '/api/auths/logout',
    method: 'delete',
  })
}

// 获取验证码
export function getCaptcha() {
  return request({
    url: '/api/auths/captcha',
    method: 'get',
    responseType: 'blob',
  })
}

// 验证验证码
export function verifyCode(code) {
  return request({
    url: '/api/auths/verifyCode/' + code,
    method: 'post',
  })
}

// 刷新token
export function refreshToken() {
  return request({
    url: '/api/auths/refresh',
    method: 'post',
  })
}

// 获取用户信息
export function getUserInfo(userType) {
  return request({
    url: '/api/user/info?userType=' + userType,
    method: 'get',
  })
}

// 上传头像
export function uploadAvatar(data) {
  return request({
    url: '/api/user/uploadAvatar',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data,
  })
}

// 修改用户密码
export function updatePassword(data) {
  return request({
    url: '/api/user',
    method: 'put',
    data,
  })
}

// 获取学生路由
export function getStudentRoute() {
  return {
    path: '/student',
    name: 'StudentLayout',
    component: '@/views/student/index.vue',
    redirect: '/student/exam',
    children: [
      {
        path: 'exam',
        name: 'StudentExam',
        component: '@/views/student/views/exam/index.vue',
      },
      {
        path: 'practice',
        name: 'StudentPractice',
        component: '@/views/student/views/practice/index.vue',
      },
      {
        path: 'prepareExam',
        name: 'prepareExam',
        component: '@/views/student/views/exam/examInformation.vue',
      },
      // 个人中心
      {
        path: 'userInfo',
        name: 'userInfo',
        component: '@/components/userInfo.vue',
      },
    ],
  }
}

// 获取管理员路由
export function getTeacherRoute() {
  return {
    path: '/teacher',
    name: 'TeacherLayout',
    component: '@/views/teacher/index.vue',
    redirect: '/teacher/home',
    children: [
      {
        path: 'home',
        name: 'TeacherHome',
        component: '@/views/teacher/views/home/index.vue',
        meta: {
          title: '首页',
          keepAlive: true,
          icon: 'HomeFilled',
          path: '/teacher/home',
        },
      },
      {
        path: 'userInfo',
        name: '',
        component: '@/components/userInfo.vue',
        meta: {
          title: '个人中心',
          isShow: false,
          path: '/teacher/userInfo',
        },
      },
      {
        path: 'usermanage',
        name: 'UserManage',
        component: '@/views/teacher/views/usermanage/index.vue',
        meta: {
          title: '用户管理',
          icon: 'UserFilled',
          path: '/teacher/usermanage',
        },
        children: [
          {
            path: 'student',
            name: 'StudentManage',
            component: '@/views/teacher/views/usermanage/student/index.vue',
            meta: {
              title: '学生管理',
              icon: 'User',
              path: '/teacher/usermanage/student',
            },
          },
          {
            path: 'teacher',
            name: 'TeacherManage',
            component: '@/views/teacher/views/usermanage/teacher/index.vue',
            meta: {
              title: '教师管理',
              icon: 'User',
              path: '/teacher/usermanage/teacher',
            },
          },
        ],
      },
      {
        path: 'classmanage',
        name: 'ClassManage',
        component: '@/views/teacher/views/classmanage/index.vue',
        meta: {
          title: '班级管理',
          icon: 'List',
          path: '/teacher/classmanage',
        },
      },
      {
        path: 'exam',
        name: 'ExamManage',
        component: '@/views/teacher/views/exam/index.vue',
        meta: {
          title: '考试管理',
          icon: 'Document',
          path: '/teacher/exam',
        },
      },
      {
        path: 'addexam',
        name: 'AddExam',
        component: '@/views/teacher/views/exam/addexam.vue',
        meta: {
          title: '添加考试',
          path: '/teacher/addexam',
          isShow: false,
        },
      },
      {
        path: 'question',
        name: 'QuestionBank',
        component: '@/views/teacher/views/question/index.vue',
        meta: {
          title: '题库管理',
          icon: 'FolderOpened',
          path: '/teacher/question',
        },
      },
      {
        path: 'testquestions',
        name: 'TestQuestions',
        component: '@/views/teacher/views/testquestions/index.vue',
        meta: {
          title: '试题管理',
          icon: 'DocumentCopy',
          path: '/teacher/testquestions',
        },
      },
      {
        path: 'addquestion',
        name: 'AddQuestion',
        component: '@/views/teacher/views/testquestions/addQuestion.vue',
        meta: {
          title: '添加试题',
          icon: 'DocumentCopy',
          path: '/teacher/addquestion',
          isShow: false,
        },
      },
      {
        path: 'score',
        name: 'Score',
        component: '@/views/teacher/views/score/index.vue',
        meta: {
          title: '成绩查询',
          icon: 'List',
          path: '/teacher/score',
        },
      },
    ],
  }
}
